package com.cskaoyan.controller.backStage;

import com.cskaoyan.mapper.TopicMapper;
import com.cskaoyan.model.Topic;
import com.cskaoyan.model.bo.TopicDeletBO;
import com.cskaoyan.model.bo.TopicListBO;
import com.cskaoyan.model.vo.*;
import com.cskaoyan.service.TopicService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: TopicController
 * @Description: 专题模块
 * @Author:YPS
 * @Date: 2022/5/6 15:57
 * @Version: 1.0
 **/
@RestController
@RequestMapping("admin/topic")
public class TopicController {
    @Autowired
    TopicService topicService;
    @RequiresPermissions("admin:topic:list")
    @RequestMapping("list")
    public BaseRespVO<DataVO> topicList(TopicListBO topicListBO){
        DataVO<Topic> topicDataVO = topicService.queryTopic(topicListBO);
        return BaseRespVO.ok(topicDataVO);
    }
    @RequiresPermissions("admin:topic:create")
    @RequestMapping("create")
    public BaseRespVO<Topic> createTopic(@RequestBody Topic topic){
        Topic topi = topicService.createTopic(topic);
        return BaseRespVO.ok(topi);
    }
    @RequiresPermissions("admin:topic:read")
    @RequestMapping("read")
    public BaseRespVO<TopicReadVO> readTopic(Integer id){
        TopicReadVO topicReadVO = topicService.readTopic(id);
        return BaseRespVO.ok(topicReadVO);
    }
    @RequiresPermissions("admin:topic:update")
    @RequestMapping("update")
    public BaseRespVO<Topic> updateTopic(@RequestBody Topic topic){
        Topic top = topicService.updateTopic(topic);
        return BaseRespVO.ok(top);
    }
    @RequiresPermissions("admin:topic:delete")
    @RequestMapping("delete")
    public ExceptionVO deleteTopic(@RequestBody Topic topic){
        topicService.deleteTopic(topic);
        return new ExceptionVO();
    }
    @RequiresPermissions("admin:topic:batch-delete")
    @RequestMapping("batch-delete")
    public ExceptionVO batchDeleteTopic(@RequestBody TopicDeletBO topicDeletBO){
        Integer[] ids = topicDeletBO.getIds();
        topicService.batchDelete(ids);
        return new ExceptionVO();
    }
}
